<!doctype html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>后台登录</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <link rel="stylesheet" href="./lib/layui/css/layui.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <link rel="shortcut icon" href="images/logo.php">
</head>
<body>
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form"  target="nm_iframe">
                <div class="layui-form-item">
                    <label class="layui-form-label">
                        <span class="x-red">*</span>用户ID
                    </label>
                    <div class="layui-input-inline">
                        <input  onblur="" type="text" id="uid" name="uid" required="required" lay-verify="nikename"
                                autocomplete="off" class="layui-input" value="">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <span class="x-red">*</span>城市
                    </label>
                    <div class="layui-input-inline">
                        <input  type="text" id="city" name="city" required="required" lay-verify="nikename"
                                autocomplete="off" class="layui-input"  value="浙江省杭州市" readonly="readonly">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label  class="layui-form-label">
                        <span class="x-red">*</span>地址
                    </label>
                    <div class="layui-input-inline" onclick="obtainNumber()">
                        <select name="address" id="address" >
                            <option value="">请选择</option>
                            <tbody id="bg" th:each="address :${#session.getAttribute('address')}">
                            <option  th:value="${address}">[[${address}]]</option>
                            </tbody>
                        </select>
                    </div>
                </div>
            <div>
                <label  class="layui-form-label">
                    <span class="x-red">*</span>车位编号
                </label>
                <div class="layui-input-inline" >
                    <select name="number" id="number" lay-ignore>
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>

                <div class="layui-form-item">
                    <label  class="layui-form-label">
                    </label>
                    <button  class="layui-btn" lay-filter="add" lay-submit="" onclick="member_add()">
                        增加
                    </button>
                </div>
            </form>
        </div>
    </div>
</div>
<iframe id="id_iframe" name="nm_iframe" style="display:none;"></iframe>
<script>
    var brandId;
    function member_add() {
        var i = $("#address").val();
        var k = $("#number").val();
        if (i == "" || k == "") {
            layer.msg("请填写完整！", {icon: 2, time: 1000});
        }else {
            $.ajax({
                url: "/admin/addUserParking",
                type: "POST",
                data: {
                    "uid": $("#uid").val(),
                    "number": k,
                    "city": $("#city").val(),
                    "address": i,
                },
                success: function (data) {
                    if (data == '') {
                        layer.msg('添加成功！', {icon: 1, time: 3000});
                        myrefresh();
                    } else {
                        layer.msg(data, {icon: 2, time: 1000});
                    }
                }
            })
        }

    }

    function obtainNumber(){
        if($("#address").val()==""||$("#address").val()==brandId){
        }else {
            brandId =$("#address").val()
            $.ajax({
                url: "/admin/obtainNumber",
                type: "POST",
                data: {
                    "address": brandId
                },
                success: function (data) {
                        var html="<option value=\"\">请选择</option>";
                        for (var i=0;i<data.length;i++){
                            html +="<option>"+data[i]+"</option>"
                        }

                        $("select[name=number]").empty();
                        $("select[name=number]").append(html);
                        layui.form().render();
                }
            })
        }
    }

    function verifyUserPhone(){
        $.ajax({
            url: "/admin/VerifyRealUId",
            type: "POST",
            data: {
                "id": $("#uid").val()
            },
            success: function (data) {
                if(data!='') {
                    layer.msg(data, {icon: 2, time: 1000});
                }
            }
        })

    }

    function myrefresh(){
        window.location.href="/userParking";
        window.parent.location.href="/userParking";
    }
</script>
</body>
</html>
